<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  comment_model.php
//  www.6block.com
//  
//  Created by Will_Lee on 2011-05-17.
//  Copyright 2011 lishuzu. All rights reserved.
// 

class Comment_model extends CI_model{
	function __construct(){
		parent::__construct();
	}
	
	function get_comments($aid){
		$comments = array();
		$sql = "SELECT c.*, u.weibo_url, u.avatar, u.username FROM ".$this->db->dbprefix('comments').
				" c LEFT JOIN ".$this->db->dbprefix('user')." u ON u.uid=c.uid WHERE c.aid = '".$aid."' ORDER BY c.dateline DESC";
		$query = $this->db->query($sql);
		foreach ($query->result_array() as $row) {
			$comments[] = $row;
		}
		return $comments;
	}

	function get_comment_by_cid($cid){
		$comment = array();
		if ($cid) {
			$this->db->where('cid', $cid);
			$query = $this->db->get('comments');
			$comment = $query->row_array();
			return $comment;
		}
		return false;
	}
		
	function insert_comment($comments){
		if ($comments) {
			$this->db->insert('comments', $comments);
			return $this->db->insert_id();
		}else{
			return false;
		}
	}
	
	function delete_comment($cid){
		if ($cid) {
			$this->db->where('cid', $cid);
			$this->db->delete('comments');
			return $this->db->affected_rows();;
		}else{
			return false;
		}
	}
}
/* End of file welcome.php */
/* Location: ./application/controllers/index.php */
?>